<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html>
<%
	String width = request.getParameter("width");
	String height = request.getParameter("height");
	String distance = request.getParameter("distance");
	String addr_gubun = request.getParameter("addr_gubun");
		if(addr_gubun == null) addr_gubun = "";
	String addr_dong = request.getParameter("addr_dong");
		if(addr_dong == null) addr_dong = "";
	String address = addr_gubun+addr_dong;
%>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> </script>
<script src="/js/common_lib/jquery-1.7.min.js"> </script>
<script src="/js/carcenter2/getData.js"> </script>
<script src="/js/common_lib/sencha-touch-debug-w-comments.js"> </script>
<script>
var greenIcon = new google.maps.MarkerImage(
	 "http://labs.google.com/ridefinder/images/mm_20_green.png",
	   new google.maps.Size(12, 20),
	   new google.maps.Point(0, 0),
	   new google.maps.Point(6, 20)
);

var makeMap = function(latlng , xmldata) {

	var gmap = new google.maps.Map(
		map_div , {
			zoom:16,
			center: latlng ,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}		
	);
	
	var marker = new google.maps.Marker({
		icon: greenIcon,
		position: latlng,
		map: gmap,
		title: '현재 위치'
	});
	
	var curLat , curLng , curTitle , curCate1 , curSeq;
	$(xmldata).find('item').each(function(){
		console.log($(this));
		curLat = $(this).find('lat').text();
		curLng = $(this).find('lng').text();
		curTitle = $(this).find('name').text();
		curCate1 = $(this).find('category1').text();
		curSeq = $(this).find('info_seq').text();
		if(curLat && curLng) {
			var marker = new google.maps.Marker({
				position: new google.maps.LatLng(curLat , curLng) ,
				map: gmap,
				title: curTitle
			});
			google.maps.event.addListener(marker , 'click' , function(){
			//	map.panel.make.carcenter( curSeq );
			});
		}
	});

};

$(document).ready(function(){
// common start	
	var map_div= document.getElementById("map_div");

	$('#map_div').css({
		width: <%=width%> ,
		height: <%=height%> 
	});
	
// common end
<%
if(address != null && !address.equals("")) {
%>
// 주소로 검색 start
	var address = '<%=address%>';
	var geocoder = new google.maps.Geocoder();
	geocoder.geocode( {'address' : address} , function(results ,status){
		if(status == google.maps.GeocoderStatus.OK) {
			makeMap( 
					results[0].geometry.location  , 
					getCarcInfo('xml' , '' , '' , '' , { addr_dong : '<%=addr_dong%>' , addr_gubun : '<%=addr_gubun%>' })
			);
		}
	} );

// 주소로 검색 end
<%
}
else {
%>
// 현재위치 검색 start
	navigator.geolocation.getCurrentPosition( function(position){
		
		var lat = position.coords.latitude;
		var lng = position.coords.longitude;
		var distance = '<%=distance==null? "" : distance%>';
		if(!distance) distance = 10000;
		makeMap(new google.maps.LatLng(lat , lng) , 
				getCarcInfoAround('xml' , {'lat' : lat , 'lng' : lng , 'distance' : distance }) 
		);
		
	} , function(){} , {enableHighAccuracy : true} );
// 현재위치검색 종료
<%
}
%>

// common start

// common end


});

</script>

<body>
<div id="map_div" ></div>
<span id="carcInfoXml" style="display:none;"></span>
</body>
</html>